from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import User


# Register your models here.

# admin.site.register(User)


# @admin.register(User)
# class UsersUserAdmin(UserAdmin):
#     list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'nickname')
#     list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups', 'nickname')


class UsersUserAdmin(UserAdmin):
    # add_fieldsets = (
    #     (None, {
    #         'classes': ('wide',),
    #         'fields': ('username', 'nickname', 'email', 'password1', 'password2'),
    #     }),
    # )
    def __init__(self, *args, **kwargs):
        super(UsersUserAdmin, self).__init__(*args, **kwargs)
        self.list_display = self.list_display + ('nickname',)  # 展示列
        self.list_filter = self.list_filter + ('nickname',)  # 过滤器
        self.search_fields = self.search_fields + ('nickname',)  # 搜索过滤
        self.fieldsets[1][1]['fields'] = (
            'first_name', 'last_name', 'email', 'nickname')
        self.add_fieldsets[0][1]['fields'] = ('username', 'nickname', 'email', 'password1', 'password2')


admin.site.register(User, UsersUserAdmin)
